<div id="container">
  <div id="header">
    <h1>Personal Stocks Wallet</h1>
    <p>Paweł Chmielewski</p>
  </div>

  <div id="navwrap">
    <div id="navigation">
      <a href="#"><strong><%= link_to 'Manage Accounts', :controller => 'accounts' %></strong></a>
      <a href="#"><strong><%= link_to 'Manage Shares', :controller => 'shares' %></strong></a>
      <a href="#"><strong><%= link_to 'Buy new', :action => 'buy' %></strong></a>
    </div>
  </div>

  <div id="mainBody">

    <h3><%= link_to_function "Wallet", "Element.toggle('wallet')" %></h3>
    <div class="operations" id="wallet">
      <table>
        <tbody>
          <tr>
            <th>Account</th>
            <th>Date</th>
            <th>Name</th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Net Amount</th>
            <th>Brokerage</th>
            <th>Gross Amount</th>
            <th>&nbsp;</th>
          </tr>

          <% for operation in @operations %>
          <%= render :partial => "list_item", :locals => {:operation => operation}%>
          <% end %>

          <script lang="JavaScript">
            <!--
            <%= remote_function(
            :update   => "walletTotalId",
            :url      => {:action => :walletTotal}) %>
            //-->
          </script>
          <tr id="walletTotalRow">
            <td colspan="9">
              <div id="walletTotalId">
                <%= render "index/walletTotal" %>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>

    <h3><%= link_to_function "Sandbox", "Element.toggle('sandbox')" %></h3>
    <div class="operations" id="sandbox" style="display:none;">
      <%= render "index/sandbox" %>
    </div>

    <h3><%= link_to_function "History", "Element.toggle('history')" %></h3>
    <div class="operations" id="history" style="display:none;">
      <% netAmountTotal = 0.0 %>
      <% brokerage      = 0.0 %>
      <% grossAmountTotal = 0.0 %>
      <table>
        <tbody>
          <tr>
            <th>Account</th>
            <th>Date</th>
            <th>Name</th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Net Amount</th>
            <th>Brokerage</th>
            <th>Gross Amount</th>
            <th>&nbsp;</th>
          </tr>
          <% for operation in @history %>
            <%= render :partial => "list_item", :locals => {:operation => operation}%>

              <% if operation.sold %>
              <% sold = operation.total%>
              <tr>
                <td colspan="5" align="right">TOTAL:</td>
                <td class="<%= totalColor(sold.net_amount) %>"><%= sprintf("%0.2f", sold.net_amount) %></td>
                <td class="<%= totalColorInv(sold.brokerage) %>"><%= sprintf("%0.2f", sold.brokerage) %></td>
                <td class="<%= totalColor(sold.gross_amount) %>"><%= sprintf("%0.2f", sold.gross_amount) %></td>
                <td>&nbsp;</td>
                <% netAmountTotal = netAmountTotal + sold.net_amount %>
                <% brokerage      = brokerage + sold.brokerage %>
                <% grossAmountTotal = grossAmountTotal + sold.gross_amount %>
              </tr>

            <% end %>
          <% end %>
          <tr>
            <td colspan="5" align="right">TOTAL OF TOTAL:</td>
            <td class="<%= totalColor(netAmountTotal) %>"><%= sprintf("%0.2f", netAmountTotal) %></td>
            <td class="<%= totalColorInv(brokerage) %>"><%= sprintf("%0.2f", brokerage) %></td>
            <td class="<%= totalColor(grossAmountTotal) %>"><%= sprintf("%0.2f", grossAmountTotal) %></td>
            <td>&nbsp;</td>
          </tr>
      </table>
    </div>

    <div id="footer">
      <p>by dzem</p>
    </div>

  </div>
</div>
